﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace SARUserControls
{
	/// <summary>
	/// 总体参数选项卡
	/// </summary>
	public partial class OverallTabs : UserControl
	{
		public OverallTabs()
		{
			this.InitializeComponent();
		}

        private int currentTabIndex = 0;

        /// <summary>
        /// 当前的选项卡序号
        /// </summary>
        public int SARCurrentTabIndex
        {
            get { return currentTabIndex; }
            set 
            { 
                currentTabIndex = value;
                if (currentTabIndex == 0)
                {
                    tab1Content.Margin = new Thickness(16, tab1Content.Margin.Top, tab1Content.Margin.Right, tab1Content.Margin.Bottom);
                    tab2Content.Margin = new Thickness(18, tab2Content.Margin.Top, tab2Content.Margin.Right, tab2Content.Margin.Bottom);

                    tab1.Visibility = System.Windows.Visibility.Visible;
                    tab2.Visibility = System.Windows.Visibility.Hidden;
                }
                else if (currentTabIndex == 1)
                {
                    tab1Content.Margin = new Thickness(18, tab1Content.Margin.Top, tab1Content.Margin.Right, tab1Content.Margin.Bottom);
                    tab2Content.Margin = new Thickness(16, tab2Content.Margin.Top, tab2Content.Margin.Right, tab2Content.Margin.Bottom);

                    tab1.Visibility = System.Windows.Visibility.Hidden;
                    tab2.Visibility = System.Windows.Visibility.Visible;
                }
            }
        }

        private void gridTab1Proxy_MouseEnter(object sender, MouseEventArgs e)
        {
            if (currentTabIndex != 0)
            {
                tab1Content.Margin = new Thickness(16, tab1Content.Margin.Top, tab1Content.Margin.Right, tab1Content.Margin.Bottom);
            }
        }

        private void gridTab1Proxy_MouseLeave(object sender, MouseEventArgs e)
        {
            if (currentTabIndex != 0)
            {
                tab1Content.Margin = new Thickness(18, tab1Content.Margin.Top, tab1Content.Margin.Right, tab1Content.Margin.Bottom);
            }
        }

        private void gridTab2Proxy_MouseEnter(object sender, MouseEventArgs e)
        {
            if (currentTabIndex != 1)
            {
                tab2Content.Margin = new Thickness(16, tab2Content.Margin.Top, tab2Content.Margin.Right, tab2Content.Margin.Bottom);
            }
        }

        private void gridTab2Proxy_MouseLeave(object sender, MouseEventArgs e)
        {
            if (currentTabIndex != 1)
            {
                tab2Content.Margin = new Thickness(18, tab2Content.Margin.Top, tab2Content.Margin.Right, tab2Content.Margin.Bottom);
            }
        }

        private void gridTab1Proxy_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            this.SARCurrentTabIndex = 0;
            if (SARIndexChanged != null)
            {
                SARIndexChanged.Invoke(0);
            }
        }

        private void gridTab2Proxy_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            this.SARCurrentTabIndex = 1;
            if (SARIndexChanged != null)
            {
                SARIndexChanged.Invoke(1);
            }
        }

        /// <summary>
        /// 当前序号更新事件
        /// </summary>
        public event IndexChangedHandler SARIndexChanged;
	}
}